package com.cloudspace.yunloan.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudspace.yunloan.R;
import com.cloudspace.yunloan.entity.CaseEntity;
import com.cloudspace.yunloan.mediarecorder.VideoPlayerActivity;
import com.cloudspace.yunloan.net.manager.ImageManager;

public class CaseDetailFragment extends BaseFragment implements View.OnClickListener {
    private View rootView;

    private ImageView idFrontImg;
    private ImageView idBackImg;
    private ImageView idPersonImg;

    private TextView basicInfoTv;
    private TextView extraInfoTv;

    private ImageView signVideoImg;
    private CaseEntity mEntity;

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_case_detail, container, false);

        return rootView;
    }

    @Override
    public void onFragmentCreated(Bundle savedInstanceState) {

    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        super.initView(view, savedInstanceState);

        idFrontImg = rootView.findViewById(R.id.left_img);
        idBackImg = rootView.findViewById(R.id.middle_img);
        idPersonImg = rootView.findViewById(R.id.right_img);

        basicInfoTv = rootView.findViewById(R.id.basic_info_tv);
        extraInfoTv = rootView.findViewById(R.id.extra_info_tv);

        signVideoImg = rootView.findViewById(R.id.bottom_img);
        signVideoImg.setOnClickListener(this);

        if (mEntity != null){
            basicInfoTv.setText(mEntity.name + " " + mEntity.idCard);

            String extraInfo = String.format("时间:%s 地点:%s 人员:%s",mEntity.time, mEntity.address, mEntity.involve);
            extraInfoTv.setText(extraInfo);

            ImageManager.loadImage(getActivity(), idFrontImg, mEntity.idFrontImgUrl);
            ImageManager.loadImage(getActivity(), idBackImg, mEntity.idBackImgUrl);
            ImageManager.loadImage(getActivity(), idPersonImg, mEntity.idPersonImgUrl);
            ImageManager.loadImage(getActivity(), signVideoImg, mEntity.videoImgUrl);
        }
    }

    @Override
    public void updateContent() {

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.bottom_img){
            if (mEntity != null){
                VideoPlayerActivity.showActivity(getActivity(), mEntity.videoUrl);
            }
        }
    }

    public void setData(CaseEntity entity) {
        mEntity = entity;
    }
}
